package com.zkthink.ceres.finance.dao;

import com.baomidou.mybatisplus.annotation.SqlParser;
import com.zkthink.base.mapper.SuperMapper;
import com.zkthink.ceres.finance.dto.AccountSummaryDTO;
import com.zkthink.ceres.finance.dto.JournalSummaryDTO;
import com.zkthink.ceres.finance.dto.PlatformFinanceDTO;
import com.zkthink.ceres.finance.entity.JournalDetail;

import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Repository;

import java.time.LocalDateTime;
import java.util.List;

/**
 * <p>
 * Mapper 接口
 * 流水明细表
 * </p>
 *
 * @author vivi.huang
 * @date 2020-05-25
 */
@Repository
public interface JournalDetailMapper extends SuperMapper<JournalDetail> {

    /**
     * 流水汇总分页 records
     * @param timeFormat
     * @param summaryDate
     * @param page
     * @param size
     * @return
     */
    List<JournalSummaryDTO> findJournalSummaryPage(@Param("timeFormat")String timeFormat, @Param("summaryDate")String summaryDate,
                                                   @Param("page")long page, @Param("size")long size);

    /**
     * 流水汇总total
     * @param timeFormat
     * @return
     */
    Integer getTotalOfJournalSummaryPage(@Param("timeFormat")String timeFormat, @Param("summaryDate")String summaryDate);

    /**
     * 流水明细分页total
     * @param date
     * @param paymentType
     * @param journalType
     * @return
     */
    Integer getTotalOfJournalDetailPage(@Param("timeFormat")String timeFormat, @Param("dateValue") String date, @Param("paymentType")Integer paymentType, @Param("journalType")Integer journalType);

    /**
     * 流水明细分页list
     * @param date
     * @param paymentType
     * @param journalType
     * @param page
     * @param size
     * @return
     */
    List<JournalDetail> findJournalDetailPage(@Param("timeFormat")String timeFormat, @Param("dateValue")String date,@Param("paymentType") Integer paymentType,@Param("journalType") Integer journalType, @Param("page")long page, @Param("size") long size);

    /**
     * 帐目统计情况
     * @return
     */
    @SqlParser(filter = true)
    AccountSummaryDTO getAccountSummary(@Param("tenantCode") String tenantCode);

    /**
     * 求出余额
     * @param tenantCode
     * @return
     */
    @SqlParser(filter = true)
    Long getLastBalanceOfJournalDetail(@Param("tenantCode") String tenantCode);

    /**
     *
     * 保存流水明细
     * @return
     */
    @SqlParser(filter = true)
    Boolean insertJournalDetail(JournalDetail journalDetail);

    /**
     * 平台-财务管理分页
     * @param tenantName 商家
     * @param tenantCode 商家编码
     * @param page 页数
     * @param size 页大小
     * @return
     */
    @SqlParser(filter = true)
    List<PlatformFinanceDTO> findPlatformFinancePage(@Param("tenantName")String tenantName, @Param("tenantCode")String tenantCode, @Param("page")long page, @Param("size")long size);

    /**
     * 平台-财务管理 总数
     * @param tenantName
     * @param tenantCode
     * @return
     */
    @SqlParser(filter = true)
    int getTotalOfPlatformFinancePage(@Param("tenantName")String tenantName,@Param("tenantCode") String tenantCode);

    /**
     * 平台-财务管理-总统计
     * @return
     */
    @SqlParser(filter = true)
    PlatformFinanceDTO getPlatformFinanceSummary();
}
